package com.icode.web.controller.house;

import com.icode.core.dto.house.AgreementDTO;
import com.icode.core.dto.house.HouseInfoDTO;

import com.icode.core.model.house.HouseInfo;
import com.icode.core.shared.DataToJson;
import com.icode.core.shared.StringUtils;
import com.icode.dao.HouseDao;
import com.icode.service.house.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lb
 * Date: 15-11-23
 * Time: 下午2:41
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/agreement")
public class AgreementController {

    @Autowired
    private HouseService houseService;

    @RequestMapping(value = "form", method = RequestMethod.GET)
    public ModelAndView showForm(Model model) {
        List<HouseInfoDTO> houseInfoDTOs = houseService.getHouseInfoDTOs();
        List<AgreementDTO> agreementDTOs = houseService.getAgreementDTOs();
        model.addAttribute("houseInfoDTOs", houseInfoDTOs);
        model.addAttribute("agreementDTOs",agreementDTOs);
        return new ModelAndView("back/houseBase/agreement", "agreement", new AgreementDTO());
    }

    @RequestMapping(value = "form", method = RequestMethod.POST)
    public String saveOrUpdateBannerForApp(AgreementDTO agreementDTO) {
        houseService.saveOrUpdateAgreement(agreementDTO);
        return "redirect:/agreement/form";
    }

    @RequestMapping(value = "showContent/{agreementGuid}", method = RequestMethod.GET)
    public ModelAndView showContent(@PathVariable String agreementGuid, Model model) {
        AgreementDTO agreementDTO = houseService.getAgreementDTOByGuid(agreementGuid);
        model.addAttribute("agreementDTO",agreementDTO);
        return new ModelAndView("back/houseBase/agreementcontent");
    }
}